﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Business {
    public static class Config {
        private static readonly IDictionary<string, string> _Data;

        static Config() {
            _Data = GetData().ToDictionary(_ => _.Key, _ => _.Value);
        }

        private static IEnumerable<KeyValuePair<string, string>> GetData() {
            var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ricercar.config");
            
            foreach (var line in File.ReadLines(file)) {
                if (IsComment(line) || string.IsNullOrWhiteSpace(line))
                    continue;

                var idx = line.IndexOf("=");
                var key = line.Substring(0, idx);
                var value = line.Substring(idx + 1);
                yield return new KeyValuePair<string, string>(key, value);
            }
        }

        private static bool IsComment(string line) {
            return line.StartsWith("#");
        }
        
        public static string GetValue(string configKey) {
            return _Data[configKey];
        }
    }
}
